<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<style>
.input2 {
	border: 1px solid #C8C8C8;
	padding: 3px 5px;
}
.wrc {width:250px;}
.money {width:70px}
.tbl-list td {padding: 3px 5px}
img#loading {display:none}
</style>
<div class="page-content middle padtop10">
	<!-- bread crumb -->
	<p id="bread-crumb">
		<a href="<?php echo site_url('');?>">
			<?php echo $lang['home'];?>
        </a>
		<?php echo $lang['request_recharge'];?>
	</p>
	<!-- end bread crumb -->
	
	<h3>
		<?php echo $lang['request_recharge'];?>
	</h3><br />
			
	<div class="payment-total-info myclear">
		<table style="border-spacing:3px" width="100%">
			<tr>
				<td width="90">
					<select id="slTypeAd" class="payment-by-month select" onchange="filterChange();">
						<option value="1" <?php if($typead == 1) echo 'selected="selected"';?>>
							CPC
						</option>
						<option value="2" <?php if($typead == 2) echo 'selected="selected"';?>>
							CPM4K
						</option>
					</select>
				</td>
				<td>
					<b class="ver-middle marright5"><?php echo $lang['status']?>: </b>
					<select id="slStatus" class="payment-by-month select" onchange="filterChange();">
						<?php foreach ($arr_permiss as $item){?>
						<option value="<?php echo $item?>" <?php if($status == $item) echo 'selected="selected"';?>>
							<?php echo $lang['arr_status'][$item];?>
						</option>
						<?php }?>
					</select>
				</td>
				<td>
					<input type="text" name="txtUserFilter" id="txtUserFilter" class="superblyTagfield" allowNewTags="false" number="5000" readonly="readonly" preset="<?php echo $sch_username;?>" />
				</td>
				<td style="padding-left:15px">
					<b class="ver-middle marright5"><?php echo $lang['date']?>: </b>
					<input class="input-time" type="text" id="slDate" size="30" value="<?php echo $fromdate.' / '.$todate;?>" />
				</td>
				<!-- <td style="padding-left:15px;text-align:right;width:20%">
					<input type="button" class="input2" style="cursor:pointer" value="<?php echo $lang['add_money'];?>" onclick="window.location='<?php echo site_url('recharge/addmoney');?>';" />
				</td> -->
				<td style="padding-left:15px;text-align:right;width:15%">
					<input type="button" class="input2" style="cursor:pointer" value="<?php echo $lang['create_request_recharge'];?>" onclick="window.location='<?php echo site_url('recharge/create');?>';" />
				</td>
			</tr>
		</table>
		<br />
		<table class="tbl-list" width="100%" border="1">
			<tr>
				<td width="30" class="td-label" style="text-align:center">
					<b><?php echo $lang['stt'];?></b>
				</td>
				<td width="120" class="td-label">
					<b><?php echo $lang['date'];?></b>
				</td>
				<td width="150" class="td-label">
					<b><?php echo $lang['account'];?></b>
				</td>
				<td class="td-label" width="150">
					<b><?php echo $lang['recieve_account'];?></b>
				</td>
				<td class="td-label" style="text-align:right" width="120">
					<b><?php echo $lang['amount'].' ('.$lang['currency'].')';?></b>
				</td>
				<td class="td-label">
					<b><?php echo $lang['receipts'];?></b>
				</td>
				<td class="td-label" width="50">&nbsp;</td>
			</tr>
			<?php $i = 0; foreach ($items as $item){ $i++; ?>
			<tr class="row">
				<td style="text-align:center">
					<?php echo ($i + $stt);?>
				</td>
				<td>
					<?php $date = new DateTime($item->created); echo $date->format('d-m-Y H:i:s');?>
				</td>
				<td>
					<?php echo $item->createname;?>
				</td>
				<td>
					<?php echo $item->recievename;?>
				</td>
				<td style="text-align:right;">
					<?php echo number_format($item->money);?>
				</td>
				<td>
					<?php echo $item->receipts;?>
				</td>
				<td class="text-center">
					<a href="<?php echo site_url('recharge/addetail/?id='.$item->id.'&typead='.$typead);?>">
						<?php echo $lang['detail'];?>
					</a>
				</td>
			</tr>
			<?php }?>
		</table>
		<!-- paging -->
		<div class="myclear martop20">
			<div class="brv-paging-left">
				<table class="tbl-list brv-paging" border="1">
					<tr>
						<td class="brv-paging-name">
							<?php echo $lang['page'].' '. $page.' ['.$pages.']'?>
						</td>
						
						<td class="brv-paging-pre-next">
							<img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
							<img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page < $pages ? $page + 1 : $page;?>)" />
						</td>
					</tr>
				</table>
			</div>
			<!-- important. fix for ie 6. Don't remove -->
			<!--[if IE 6]><br class="clearboth" /><![endif]-->
		</div>
		<!-- end paging -->
	</div>
</div>
<br />
<style>
.superblyTagfieldDiv{
	width: 180px;
}
</style>
<script type="text/javascript">
$('#slDate').DatePicker({
	format:'Y-m-d',
	date: ['<?php echo $fromdate;?>', '<?php echo $todate;?>'],
	current: '<?php echo date('Y-m-d');?>',
	calendars: 2,
	mode: 'range',
	starts: 1,
	position: 'bottom',
	onChange: function(formated, dates){
		$('#slDate').val(formated);
		$('#slDate').val(formated.join(' / '));
		$('#slDate').DatePickerHide();
		filterChange();
	}
});

$(document).ready(function(){
	$(function(){
		$('.tbl-list .row').mouseover(function(){
			$(this).css('background','#ffc');
		});
		$('.tbl-list .row').mouseout(function(){
			$(this).css('background','none');
		});
	});
	
	// init city location tag  suggestion
	$('.superblyTagfield').css('display', 'none');		
	var allowNewTags = false;
	var showTagsNumber = 1000;
	var preset = new Array();
	var url = '/admin/campaign/get_suggest_user';
	if($('#txtUserFilter').attr('allowNewTags') == 'false'){
		allowNewTags = false;
	}
	if($('#txtUserFilter').attr('number') != null){
		showTagsNumber = $('#txtUserFilter').attr('number');
	}
			
	if($('#txtUserFilter').attr('preset') != null){
		preset = $('#txtUserFilter').attr('preset').split(',');
	}

	var fiterUserSuggestCallBack = function()
	{
		var userid = $('.superblyTagItemHddId').val();
		var status = $('#slStatus').val();
		var date = $('#slDate').val().split(' / ');
		var typead = $('#slTypeAd').val();
		window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead + '&userid=' + userid;
	};

	superblyTagField($('#txtUserFilter'), url, preset, allowNewTags, showTagsNumber, '/images/ajaxLoading.gif', false, fiterUserSuggestCallBack, fiterUserSuggestCallBack, 'Gõ username để lựa chọn', '', '165');
	<?php
   	if($sch_userid)
   	{
	?>
	filterUserAddUser('#txtUserFilter', '<?php echo $sch_username;?>', '<?php echo $sch_userid;?>', 'Gõ username để lựa chọn');
	<?php
	}
	?>
	
});



// init category
function filterUserAddUser(tagid, name, catid, strInputDefault)
{
	strInputDefault = (typeof(strInputDefault) === 'undefined' || strInputDefault === '') ? '' : strInputDefault;
	$(tagid).parent('.superblyTagInputItem').before("<li class='superblyTagItem'><span>" + name + "</span><a onclick='goIndex();'><img alt='' src='/images/x.gif' /></a><input type='hidden' class='superblyTagItemHddId' value='" + catid + "' /></li>");
	
	var val = $(tagid).val();
	if(val == '')
	{
		$(tagid).val(catid);	
	}
	else
	{
		$(tagid).val($(tagid).val() + ',' + catid);	
	}
	
	var new_index = $(tagid).parent('.superblyTagInputItem').parent('.superblyTagItems').children('.superblyTagItem').size()-1;	
	$($(tagid).parent('.superblyTagInputItem').parent('.superblyTagItems').children('.superblyTagItem')[new_index]).children('a').click(function(e){
		//var value = $($(this).parent('.superblyTagItem').children('span')[0]).text();
		var value = $($(this).parent('.superblyTagItem').children('.superblyTagItemHddId')).val();
		removeSuggestCat(value, tagid, strInputDefault);
	});
}
function filterChange()
{
	var userid = $('.superblyTagItemHddId').val();
	var status = $('#slStatus').val();
	var date = $('#slDate').val().split(' / ');
	var typead = $('#slTypeAd').val();
	if(userid==null)
	{
		window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead;
	}
	else
	{
		window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead + '&userid=' + userid;
	}
	
}

function goPage(page)
{
	var userid = $('.superblyTagItemHddId').val();
	var status = $('#slStatus').val();
	var date = $('#slDate').val().split(' / ');
	var typead = $('#slTypeAd').val();
	if(userid==null)
	{
		window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead + '&page=' + page;
	}
	else
	{
		window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead + '&page=' + page + '&userid=' + userid;
	}
	
}

function goIndex(){
	var status = $('#slStatus').val();
	var date = $('#slDate').val().split(' / ');
	var typead = $('#slTypeAd').val();
	window.location = '<?php echo site_url('recharge/adlist');?>/?status=' + status + '&fromdate=' + date[0] + '&todate=' + date[1] + '&typead=' + typead;
}

function updateStatus(id)
{
	if(!confirm('<?php echo $lang['request_update'];?>')) return;
	var status = $('#slUpdate_' + id).val();
	$('#loading').show();
	$.ajax({
		url: '<?php echo site_url('recharge/adupdatestatus');?>/?id=' + id + '&status=' + status,
		success: function(data){
			$('#loading').hide();
			alert(data);
			window.location.reload();
		}
	});
}
</script>